#!/bin/awk -f
BEGIN{
  na["H"]=11;
  na["B"]=18;
  na["S"]=25;
  na["E"]=25;
#  elim["H2S"]=1;
#  elim["B3H2c"]=1;
#  elim["B2Hx2.2sf-anti"]=1;
#  elim["B3H2x2.3sf"]=1;
#  elim["H1"]=1;
  thstr=ARGV[1]; #dash-separated list of objects
  nth=split(thstr,tham,"-");
  for(i in tham){ths[tham[i]]=1}
  ARGV[1]="elist"; # datalist from index.cur file
  ARGV[2]="tlist"; # output from thsums script
  ARGC=3;
}
ARGIND==1{dh[$1]=$2}
ARGIND==2&&$0!~/^ *\#/{sub(/^.*\//,"",$(NF));tn=$(NF);no++;oname[no]=tn;s[no]=$0}
ARGIND==2&&FNR==1{head=$0}
END{
  n=split(head,a);
  ne=0; #eliminated terms
  for(i=2;i<=n;i++){
    cn[i]=a[i];
    if(ths[a[i]]!=1){
      ne++; nec=nec" "i-1;
    }
  }
  print n-1,ne,nec;
  for(i=2;i<=n;i++){
    printf(" %5s",a[i]);
  }print"";
  for(k=1;k<=no;k++){
    j=oname[k];
    m=split(s[k],a);
    if(elim[a[n+1]]==""&&dh[j]!=""){
      nat=0;
      for(i=2;i<=n;i++){
	if(na[cn[i]]>0){nat+=a[i]*na[cn[i]]}
      }
      mu=sprintf("%1.0f",250/nat);
      for(i=2;i<=n;i++){
	printf(" %5s",a[i]*mu);
      };
      printf(" %11.6f %i %s",dh[j]*mu,nat*mu,a[n+1]);
      print"";
    }
  };
}
